/*
*************************************************************************
*西瑞克斯研发管理系统
*版 本: 1.0   
*日 期：02/09/2012    
*作 者： 王浩 QQ：873987060   
*************************************************************************   
*/ 
package com.application.yfprojectapproval.struts.actions;
import java.io.File;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.application.attachment.entity.Attachment;
import com.application.attachment.service.AttachmentService;
import com.application.attachment.struts.form.AttachmentForm;
import com.application.usertable.entity.Usertable;
import com.application.yfexamine.entity.YfExmaine;
import com.application.yfexamine.service.YfExmaineService;
import com.application.yfexamine.struts.form.YfExmaineForm;
import com.application.yfprojectapproval.commons.Constants;
import com.application.yfprojectapproval.entity.YfProjectApproval;
import com.application.yfprojectapproval.service.YfProjectApprovalService;
import com.application.yfprojectapproval.struts.form.YfProjectApprovalForm;
import com.application.yfprojectteams.entity.YfProjectTeams;
import com.application.yfprojectteams.service.YfProjectTeamsService;
import com.application.yfprojectteams.struts.form.YfProjectTeamsForm;
import com.manager.commons.CommonUtil;
import com.manager.commons.DisplayTagPageBean;
import com.manager.commons.RandomKey;
import com.manager.commons.page.PageBean;
import com.manager.workflow.WorkFlowConstants;
import com.manager.workflow.core.WorkFlowCommon;
import com.manager.workflow.core.YfWorkFlowDefine;
 /**
 * 
 * Description:YfProjectApprovalAction<br />
 * 
 * Version:V0.1<br />
 * 
 * Author: 王浩 QQ：873987060    <br />
 * 
 * History: <br />
 * 
 * 02/09/2012 
 * 
 */
public class YfProjectApprovalAction extends DispatchAction
{
       
       /**
	 * Service层实例
	 */
	private YfProjectApprovalService yfProjectApprovalService;

	private AttachmentService attachmentService;
	
	private WorkFlowCommon workFlowCommon;
	
	private YfExmaineService yfExmaineService;
	
	private YfProjectTeamsService yfProjectTeamsService;
	/**
	 * 日志
	 */
	private Logger log = Logger.getLogger(this.getClass());

	/**
	 * 实体对象
	 */
        private YfProjectApproval yfProjectApproval;


        /**
	 * 采用partialList方式分页程序
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public ActionForward getYfProjectApprovalPartialList(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.debug("searchYfProjectApproval" + "开始");
		YfProjectApprovalForm yfProjectApproval = (YfProjectApprovalForm)form;
		// 统计总记录数的sql语句
		int resultSize = 0;
		// 初始化pageBean供分页所用
		PageBean pageBean = null;
		// 取得当前页list数据
		List yfProjectApprovalList = null;
		resultSize = yfProjectApprovalService.getAllCountYfProjectApproval(yfProjectApproval);
		pageBean = PageBean.getPageBean("yfProjectApprovalTab", resultSize,request);
		yfProjectApprovalList = yfProjectApprovalService.searchYfProjectApproval(yfProjectApproval,pageBean);
		request.setAttribute("yfProjectApprovalList", yfProjectApprovalList);
		request.setAttribute("orgSelect", CommonUtil.getOrgSelectNoZB());

		log.debug("searchYfProjectApproval" + "结束");

		return mapping.findForward(Constants.SUCCESS);
	}
	
	
	public ActionForward popuSelectApprovalList(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.debug("popuSelectApprovalList" + "开始");
		YfProjectApprovalForm yfProjectApproval = (YfProjectApprovalForm)form;
		// 统计总记录数的sql语句
		int resultSize = 0;
		// 初始化pageBean供分页所用
		PageBean pageBean = null;
		// 取得当前页list数据
		List yfProjectApprovalList = null;
		resultSize = yfProjectApprovalService.getAllCountYfProjectApproval(yfProjectApproval);
		pageBean = PageBean.getPageBean("yfProjectApprovalTab", resultSize,request);
		yfProjectApprovalList = yfProjectApprovalService.searchYfProjectApproval(yfProjectApproval,pageBean);
		request.setAttribute("yfProjectApprovalList", yfProjectApprovalList);
		request.setAttribute("orgSelect", CommonUtil.getOrgSelectNoZB());
		log.debug("popuSelectApprovalList" + "结束");

		return mapping.findForward(Constants.SUCCESS);
	}

        /**
	 * 到达新增页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward toAddYfProjectApproval(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("toAddYfProjectApprovals");
		YfProjectApprovalForm yfProjectApprovalForm = (YfProjectApprovalForm) form;
		yfProjectApprovalForm.setId(RandomKey.generateID_Long_19());
		yfProjectApprovalForm.setOwnYear(Long.valueOf(CommonUtil.getCurrentYear()));
		yfProjectApprovalForm.setRname(CommonUtil.getCurrentUser(request).getRname());
		yfProjectApprovalForm.setProjectManager(CommonUtil.getCurrentUser(request).getId());
		request.setAttribute("orgSelect", CommonUtil.getOrgSelectNoZB());
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 增加
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward addYfProjectApproval(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("addYfProjectApprovals");
		YfProjectApproval yfProjectApproval = this.getYfProjectApproval(form);
		yfProjectApproval.setAuditStatus(WorkFlowConstants.AUDIT_STATUS_1);
		yfProjectApproval.setOperateid(CommonUtil.getCurrentUser(request).getId());
		yfProjectApproval.setCreateDate(new Date());
		this.yfProjectApprovalService.insertObject(yfProjectApproval);
		addProjectTeams(request, yfProjectApproval);
		
		
		return mapping.findForward(Constants.SUCCESS);
	}
    
	
	private void addProjectTeams(HttpServletRequest request,YfProjectApproval yfProjectApproval) throws Exception {
		YfProjectTeams projectteams = null;
		Map parmMap = request.getParameterMap();
		Iterator it = parmMap.entrySet().iterator();
		Map projectTeamsMap = new HashMap();
		while (it.hasNext()) {
			Map.Entry entry = (Entry) it.next();
			String key = (String) entry.getKey();
			if(key.indexOf("*") < 0 || key.indexOf("model") < 0) {
				continue;
			}
			String value = ((String[]) entry.getValue())[0];
			String pre = key.substring(0, key.indexOf("*"));
			String property = key.substring(key.indexOf("*") + 1);
			if(projectTeamsMap.containsKey(pre)) {
				projectteams = (YfProjectTeams) projectTeamsMap.get(pre);
				BeanUtils.setProperty(projectteams, property, value);
			} else {
				projectteams = new YfProjectTeams();
				BeanUtils.setProperty(projectteams, property, value);
				projectTeamsMap.put(pre, projectteams);
			}

		}
		Iterator its = projectTeamsMap.values().iterator();
		int i = 10;
		while (its.hasNext()) {
			projectteams = (YfProjectTeams) its.next();
			if(projectteams.getOrdernum()==null){
				projectteams.setOrdernum(i);
			}
			projectteams.setId(RandomKey.generateID_Long_19());
			projectteams.setApproveId(yfProjectApproval.getId());
			projectteams.setProjectNo(yfProjectApproval.getProjectNo());
			projectteams.setOperateid(CommonUtil.getCurrentUser(request).getId());
			projectteams.setCreateDate(new Date());
			this.yfProjectTeamsService.insertObject(projectteams);
			i++;
		}
	}
	
	
	/**
	 * 删除
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward deleteYfProjectApproval(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("deleteYfProjectApprovals");
		YfProjectApprovalForm yfProjectApprovalForm = (YfProjectApprovalForm) form;
		this.yfProjectApprovalService.deleteYfProjectApprovals(yfProjectApprovalForm);
		String serverPath=CommonUtil.ATTACHE_FILE;
		if(StringUtils.isBlank(serverPath)){
			serverPath=request.getSession().getServletContext().getRealPath("/"); 
		}
		AttachmentForm attachmentForm = new AttachmentForm();
		attachmentForm.setFid(yfProjectApprovalForm.getId().toString());
		attachmentForm.setType(com.manager.commons.Constants.FJ_TYPE_LXSQ);
		List<Attachment> attachment = attachmentService.queryAttachment(attachmentForm);
		if(attachment!=null && attachment.size()>0){
			for (Attachment attachment2 : attachment) {
				File file = new File(serverPath + attachment2.getUrl());
		        file.delete();
				attachmentService.deleteObject(attachment2);
				
			}
		}
		YfProjectTeamsForm yfProjectTeamsForm = new YfProjectTeamsForm();
		yfProjectTeamsForm.setApproveId(yfProjectApprovalForm.getId());
		this.yfProjectTeamsService.deleteYfProjectTeamss(yfProjectTeamsForm);
		
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 到达更新页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward toUpdateYfProjectApproval(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("toUpdateYfProjectApprovals");
		YfProjectApprovalForm yfProjectApprovalForm = (YfProjectApprovalForm) form;
		yfProjectApproval = this.yfProjectApprovalService.searchYfProjectApproval(yfProjectApprovalForm, null).get(0);
		request.setAttribute(Constants.YFPROJECTAPPROVAL, yfProjectApproval);
		
		YfProjectTeamsForm yfProjectTeamsForm = new YfProjectTeamsForm();
		yfProjectTeamsForm.setApproveId(yfProjectApproval.getId());
		List projectTeamsList = this.yfProjectTeamsService.searchYfProjectTeams(yfProjectTeamsForm, null);
		if(projectTeamsList != null && projectTeamsList.size() > 0) {
			request.setAttribute("projectTeamsList", projectTeamsList);
		}
		request.setAttribute("projectTeamsCount", projectTeamsList == null ? 0 : projectTeamsList.size());
		request.setAttribute("orgSelect", CommonUtil.getOrgSelectNoZB());
		
		if(yfProjectApprovalForm.getType()==1){
			return mapping.findForward("modify");
		}
		return mapping.findForward(Constants.SUCCESS);
	}
	
	
	

        
	/**
	 * 更新
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward updateYfProjectApproval(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("updateYfProjectApprovals");
		YfProjectApproval yfProjectApproval = this.getYfProjectApproval(form);
	    yfProjectApproval.setOperateid(CommonUtil.getCurrentUser(request).getId());
		yfProjectApproval.setCreateDate(new Date());
		this.yfProjectApprovalService.updateObject(yfProjectApproval);
		YfProjectTeamsForm yfProjectTeamsForm = new YfProjectTeamsForm();
		yfProjectTeamsForm.setApproveId(yfProjectApproval.getId());
		this.yfProjectTeamsService.deleteYfProjectTeamss(yfProjectTeamsForm);
		addProjectTeams(request, yfProjectApproval);
		return mapping.findForward(Constants.SUCCESS);
	}
	
	/**
	 * 更新
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward updatePerson(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("updatePerson");
		YfProjectApproval yfProjectApproval = this.getYfProjectApproval(form);
		YfProjectTeamsForm yfProjectTeamsForm = new YfProjectTeamsForm();
		yfProjectTeamsForm.setApproveId(yfProjectApproval.getId());
		this.yfProjectTeamsService.deleteYfProjectTeamss(yfProjectTeamsForm);
		addProjectTeams(request, yfProjectApproval);
		return mapping.findForward(Constants.SUCCESS);
	}
	    
	/**
	 * 查看页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward viewYfProjectApproval(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		log.debug("viewYfProjectApproval");
		YfProjectApprovalForm yfProjectApprovalForm = (YfProjectApprovalForm) form;
		if(StringUtils.isBlank(yfProjectApprovalForm.getId())){
			String bussId = request.getParameter("bussId");
			yfProjectApprovalForm.setId(bussId);
		}
		yfProjectApproval = this.yfProjectApprovalService.searchYfProjectApproval(yfProjectApprovalForm, null).get(0);
		String workItemId = request.getParameter("workItemId");
		yfProjectApproval.setWorkItemId(workItemId);
		request.setAttribute(Constants.YFPROJECTAPPROVAL, yfProjectApproval);
		String processId = yfProjectApproval.getProcessId();
		if(StringUtils.isNotBlank(processId)){
			examineList(processId,yfExmaineService,request);
		}	
		
		YfProjectTeamsForm yfProjectTeamsForm = new YfProjectTeamsForm();
		yfProjectTeamsForm.setApproveId(yfProjectApproval.getId());
		List projectTeamsList = this.yfProjectTeamsService.searchYfProjectTeams(yfProjectTeamsForm, null);
		if(projectTeamsList != null && projectTeamsList.size() > 0) {
			request.setAttribute("projectTeamsList", projectTeamsList);
		}
		request.setAttribute("orgSelect", CommonUtil.getOrgSelectNoZB());
		return mapping.findForward(Constants.SUCCESS);
	}

	// get--set
	/**
	 * @return the YfProjectApprovalService
	 */
	public YfProjectApprovalService getYfProjectApprovalService() {
		return this.yfProjectApprovalService;
	}

	/**
	 * @param YfProjectApprovalService
	 *  the YfProjectApprovalService to set
	 */
	public void setYfProjectApprovalService(YfProjectApprovalService yfProjectApprovalService) {
		this.yfProjectApprovalService = yfProjectApprovalService;
	}

	/**
	 * 获取YfProjectApproval实体
	 * @param ActionForm
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 * @return the YfProjectApproval
	 */
	public YfProjectApproval getYfProjectApproval(ActionForm form) throws IllegalAccessException, InvocationTargetException {
		YfProjectApprovalForm yfProjectApprovalForm = (YfProjectApprovalForm) form;
		yfProjectApproval = new YfProjectApproval();
		BeanUtils.copyProperties(yfProjectApproval, yfProjectApprovalForm);
		return yfProjectApproval;
	}
    
        public void setYfProjectApproval(YfProjectApproval yfProjectApproval) {
		this.yfProjectApproval = yfProjectApproval;
	}

		public void setAttachmentService(AttachmentService attachmentService) {
			this.attachmentService = attachmentService;
		}

		public void setWorkFlowCommon(WorkFlowCommon workFlowCommon) {
			this.workFlowCommon = workFlowCommon;
		}
		/**
		 * 提交审核
		 * 
		 * @param mapping
		 * @param form
		 * @param request
		 * @param response
		 * @return ActionForward
		 * @throws Exception
		 */
		public ActionForward submitWorkFlow(ActionMapping mapping, ActionForm form,
				HttpServletRequest request, HttpServletResponse response)
				throws Exception {
			log.debug("submitYfProjectApproval");
			String submitType = request.getParameter("submitType");
			//新增界面直接提交
			if(StringUtils.isNotBlank(submitType) && "add".equals(submitType)){
				yfProjectApproval = this.getYfProjectApproval(form);
				yfProjectApproval.setOperateid(CommonUtil.getCurrentUser(request).getId());
				yfProjectApproval.setCreateDate(new Date());
				this.yfProjectApprovalService.insertObject(yfProjectApproval);
				addProjectTeams(request, yfProjectApproval);
			}
			if(StringUtils.isNotBlank(submitType) && "update".equals(submitType)){
				yfProjectApproval = this.getYfProjectApproval(form);
				
				YfProjectApprovalForm tempForm = new YfProjectApprovalForm();
				tempForm.setId(yfProjectApproval.getId());
				YfProjectApproval old = yfProjectApprovalService.searchYfProjectApproval(tempForm,null).get(0);
				yfProjectApproval.setProjectType(old.getProjectType());
				yfProjectApproval.setProjectOrg(old.getProjectName());
				YfProjectTeamsForm yfProjectTeamsForm = new YfProjectTeamsForm();
				yfProjectTeamsForm.setApproveId(yfProjectApproval.getId());
				this.yfProjectTeamsService.deleteYfProjectTeamss(yfProjectTeamsForm);
				addProjectTeams(request, yfProjectApproval);
				
			}else{
				YfProjectApprovalForm yfProjectApprovalForm = (YfProjectApprovalForm) form;
				YfProjectApprovalForm tempForm = new YfProjectApprovalForm();
				tempForm.setId(yfProjectApprovalForm.getId());
				yfProjectApproval = yfProjectApprovalService.searchYfProjectApproval(tempForm,null).get(0);
			}
			Map<String,String> mapVar = new HashMap<String,String>();
			mapVar.put("bussId", yfProjectApproval.getId().toString());
			mapVar.put("bussType", WorkFlowConstants.BUSS_TYPE_LXSQ.toString());
			mapVar.put("projectName", yfProjectApproval.getProjectName().toString());
			mapVar.put("projectType", yfProjectApproval.getProjectType().toString());
			mapVar.put("projectOrg", yfProjectApproval.getProjectOrg().toString());
			mapVar.put("projectNo", yfProjectApproval.getProjectNo().toString());
			mapVar.put("ownYear", yfProjectApproval.getOwnYear().toString());
			CommonUtil.putMapVar(request,mapVar);
	 
			
			String processId = workFlowCommon.startFlow(WorkFlowConstants.PORCESS_DEFINITION_ONE,CommonUtil.getCurrentUser(request).getId(),mapVar);
		
			yfProjectApproval.setProcessId(processId);
			yfProjectApproval.setAuditStatus(WorkFlowConstants.AUDIT_STATUS_2);
		    yfProjectApproval.setOperateid(CommonUtil.getCurrentUser(request).getId());
			yfProjectApproval.setCreateDate(new Date());
			this.yfProjectApprovalService.updateObject(yfProjectApproval);
			return mapping.findForward(Constants.SUCCESS);
		}	
		
		/**
		 * 进入审核页面
		 * @param mapping
		 * @param form
		 * @param request
		 * @param response
		 * @return ActionForward
		 * @throws Exception
		 */
		public ActionForward toAuditYfProjectApproval(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
			log.debug("toAuditYfProjectApproval");
			YfProjectApprovalForm yfProjectApprovalForm = (YfProjectApprovalForm) form;
			String bussId = request.getParameter("bussId");
			String processId = request.getParameter("processId");
			String workItemId = request.getParameter("workItemId");
			String auditRole = request.getParameter("auditRole");
			String bussType = request.getParameter("bussType");
			yfProjectApprovalForm.setId(bussId);
			yfProjectApproval = this.yfProjectApprovalService.searchYfProjectApproval(yfProjectApprovalForm, null).get(0);
			yfProjectApproval.setWorkItemId(workItemId);
			request.setAttribute(Constants.YFPROJECTAPPROVAL, yfProjectApproval);
			request.setAttribute("auditRole", auditRole);
			request.setAttribute("bussType",bussType);
			
			examineList(processId,yfExmaineService,request);
			
			YfProjectTeamsForm yfProjectTeamsForm = new YfProjectTeamsForm();
			yfProjectTeamsForm.setApproveId(yfProjectApproval.getId());
			List projectTeamsList = this.yfProjectTeamsService.searchYfProjectTeams(yfProjectTeamsForm, null);
			if(projectTeamsList != null && projectTeamsList.size() > 0) {
				request.setAttribute("projectTeamsList", projectTeamsList);
			}
			
			request.setAttribute("orgSelect", CommonUtil.getOrgSelectNoZB());
			return mapping.findForward(Constants.SUCCESS);
		}
		
		/**
		 * 处理审批 提交流程
		 * @param mapping
		 * @param form
		 * @param request
		 * @param response
		 * @return
		 * @throws Exception
		 */
		public ActionForward commandFlowYfProjectApproval(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
			log.debug("commandFlowYfProjectApproval");
			YfProjectApprovalForm yfProjectApprovalForm = (YfProjectApprovalForm) form;
			yfProjectApproval = this.yfProjectApprovalService.searchYfProjectApproval(yfProjectApprovalForm, null).get(0);
			YfExmaine examine = addYfExmaine(yfProjectApprovalForm,request);

			Map processVar = new HashMap();
			//不为打回修改完成后提交
			if(!examine.getExamineFlag().equals("modify")){
				yfExmaineService.insertObject(examine);
				if(examine.getExamineFlag().equals(WorkFlowConstants.AUDIT_STATUS_AGREE)){
					processVar.put("approveFlag","agree");
					Usertable user = (Usertable) request.getSession().getAttribute("loginUser");
					String roleName = user.getRoleList().get(0).getName();
					if(roleName.equals(WorkFlowConstants.ROLE_FGFZ)){
						yfProjectApproval.setAuditStatus(WorkFlowConstants.AUDIT_STATUS_3);
						yfProjectApprovalService.updateObject(yfProjectApproval);
					}
				}else if(examine.getExamineFlag().equals(WorkFlowConstants.AUDIT_STATUS_DISAGREE)){
					processVar.put("approveFlag","disagree");
					yfProjectApproval.setAuditStatus(WorkFlowConstants.AUDIT_STATUS_4);
					yfProjectApprovalService.updateObject(yfProjectApproval);
				}
			}
			
			
			processVar.put("bussId", yfProjectApproval.getId().toString());
			processVar.put("bussType", WorkFlowConstants.BUSS_TYPE_LXSQ.toString());
			processVar.put("projectName", yfProjectApproval.getProjectName().toString());
			processVar.put("projectType", yfProjectApproval.getProjectType().toString());
			processVar.put("projectOrg", yfProjectApproval.getProjectOrg().toString());
			processVar.put("projectNo", yfProjectApproval.getProjectNo().toString());
			processVar.put("ownYear", yfProjectApproval.getOwnYear().toString());
			/**
			 * 打回修改后需要提交  根据角色决定流程路径
			 */
			CommonUtil.putMapVar(request,processVar);
			processVar.put("yfbussTaskType",WorkFlowConstants.BUSS_TASK_TYPE_NORMAL);
			String workItemId = yfProjectApprovalForm.getWorkItemId();
			if(examine.getExamineFlag().equals(WorkFlowConstants.AUDIT_STATUS_REBACK)){
				processVar.put("yfbussTaskType",WorkFlowConstants.BUSS_TASK_TYPE_REBACK);
				//如果记录operatorid 人  的角色为研发经理的时候，回退就需要跳过研发经理审批  流程开始的参数须为 START_YFJL
				String operateId = yfProjectApproval.getOperateid();
				if(CommonUtil.isYFJL(operateId)){
					workFlowCommon.commandFlowReback(workItemId, processVar,YfWorkFlowDefine.START_YFJL);
				}else{
					workFlowCommon.commandFlowReback(workItemId, processVar);
				}
			}else{
				workFlowCommon.commandFlow(workItemId, processVar);
			}
			return mapping.findForward(Constants.SUCCESS);
		}
		
		/**
		 * Description: TODO 组合审批意见对象,添加
		 * 
		 * @param form
		 * @param request
		 * @return ActionForward
		 */
		public YfExmaine addYfExmaine(ActionForm form, HttpServletRequest request) {

			YfProjectApprovalForm yfProjectApprovalForm = (YfProjectApprovalForm) form;
			// 审核标识
			String examineFlag = yfProjectApprovalForm.getExamineFlag();
			// 审核意见
			String examineOption = yfProjectApprovalForm.getExamineOption();
			String processId = yfProjectApprovalForm.getProcessId();
			YfExmaine yfExmaine = new YfExmaine();
			 
			yfExmaine.setId(RandomKey.generateID_Long_19());
			yfExmaine.setExamineFlag(examineFlag);
			yfExmaine.setExamineOption(examineOption);
			yfExmaine.setProcessId(processId);
			yfExmaine.setExamineDate(new Date());
			if(request.getSession().getAttribute("loginUser")!=null){
				Usertable curUser = (Usertable) request.getSession().getAttribute("loginUser");
				yfExmaine.setExaminePerson(curUser.getRname());
				if(curUser.getRoleList().size()>1){
					String roleName = workFlowCommon.getRoleNameByActivityId(yfProjectApprovalForm.getWorkItemId());
					yfExmaine.setExamineOrg(roleName);
				}else{
					yfExmaine.setExamineOrg(curUser.getRoleList().get(0).getName()); //无法处理同一个人有多个审批角色
				}
				
			}
			return yfExmaine;
		}
		
		
		
   
		 /*
		 * Description: TODO 查看显示意见
		 * 
		 * @param processInsId
		 * @param examine
		 * @param examineService
		 * @param examineLis
		 * @param request
		 *        void
		 */
		public void examineList(String processInsId, YfExmaineService yfExmaineService, HttpServletRequest request) throws Exception {
			YfExmaineForm yfExmaineForm = new YfExmaineForm();
			yfExmaineForm.setProcessId(processInsId);
			// 审批列表
			List<YfExmaine> examineList = yfExmaineService.searchYfExmaine(yfExmaineForm, null);
			// 防止页面出错
			int resultSize = 0;
			if(examineList != null && !examineList.isEmpty()) {
				resultSize = examineList.size();
			}
			DisplayTagPageBean.getPageBean("examine", resultSize, 0, request);
			request.setAttribute("examineList", examineList);

		}
		
		
		/**
		 * 到达更新页面
		 * 
		 * @param mapping
		 * @param form
		 * @param request
		 * @param response
		 * @return ActionForward
		 * @throws Exception
		 */
		public ActionForward toUpdateInc(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
			log.debug("toUpdateInc");
			String id = request.getParameter("id") == null ? "" : request.getParameter("id").toString();
			YfProjectApprovalForm yfProjectApprovalForm = (YfProjectApprovalForm) form;
			yfProjectApprovalForm.setId(id);
			yfProjectApproval = this.yfProjectApprovalService.searchYfProjectApproval(yfProjectApprovalForm, null).get(0);
			request.setAttribute(Constants.YFPROJECTAPPROVAL, yfProjectApproval);
			
			YfProjectTeamsForm yfProjectTeamsForm = new YfProjectTeamsForm();
			yfProjectTeamsForm.setApproveId(yfProjectApproval.getId());
			List projectTeamsList = this.yfProjectTeamsService.searchYfProjectTeams(yfProjectTeamsForm, null);
			if(projectTeamsList != null && projectTeamsList.size() > 0) {
				request.setAttribute("projectTeamsList", projectTeamsList);
			}
			request.setAttribute("projectTeamsCount", projectTeamsList == null ? 0 : projectTeamsList.size());
			request.setAttribute("orgSelect", CommonUtil.getOrgSelectNoZB());
			return mapping.findForward(Constants.SUCCESS);
		}
		
		/**
		 * 更新
		 * 
		 * @param mapping
		 * @param form
		 * @param request
		 * @param response
		 * @return ActionForward
		 * @throws Exception
		 */
		public ActionForward updateInc(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
			log.debug("updateInc");
			String id = request.getParameter("id") == null ? "" : request.getParameter("id").toString();
            
			YfProjectApproval yfProjectApproval = this.getYfProjectApproval(form);
		    yfProjectApproval.setOperateid(CommonUtil.getCurrentUser(request).getId());
			yfProjectApproval.setCreateDate(new Date());
			this.yfProjectApprovalService.updateObject(yfProjectApproval);
			
			YfProjectTeamsForm yfProjectTeamsForm = new YfProjectTeamsForm();
			yfProjectTeamsForm.setApproveId(yfProjectApproval.getId());
			this.yfProjectTeamsService.deleteYfProjectTeamss(yfProjectTeamsForm);
			addProjectTeams(request, yfProjectApproval);
			
			
			PrintWriter out = response.getWriter();
			out.print("<script>window.opener.document.location.reload(); self.close();</script>");
			return null;
		}
		
		
		
		public YfExmaineService getYfExmaineService() {
			return yfExmaineService;
		}

		public void setYfExmaineService(YfExmaineService yfExmaineService) {
			this.yfExmaineService = yfExmaineService;
		}



		public YfProjectTeamsService getYfProjectTeamsService() {
			return yfProjectTeamsService;
		}

		public void setYfProjectTeamsService(YfProjectTeamsService yfProjectTeamsService) {
			this.yfProjectTeamsService = yfProjectTeamsService;
		}
		

}
